﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;

namespace OgilvyOne.UKNow.Utility
{
    [DataContract]
    public class PageOfItems<T> : ICollection<T>
    {
        #region PageOfItems
        public PageOfItems()
        {
            Data = new List<T>();

        }

        [DataMember(Name = "list")]
        public List<T> Data { get; set; }

        /// <summary>
        /// 当前页码
        /// </summary>
        [DataMember(Name = "current_page")]
        public int PageIndex { get; set; }

        /// <summary>
        /// 页面尺寸
        /// </summary>

        public int PageSize { get; set; }

        /// <summary>
        /// 总记录数
        /// </summary>
        [DataMember(Name = "total")]
        public int TotalItemCount { get; set; }

        /// <summary>
        /// 总页数
        /// </summary>
        [DataMember(Name = "page_count")]
        public int TotalPageCount { get; set; }

        /// <summary>
        /// 是否有上一页
        /// </summary>
        public bool IsPreviousPage
        {
            get;
            set;
        }

        /// <summary>
        /// 是否有下一页
        /// </summary>
        public bool IsNextPage
        {
            get;
            set;
        }
        #endregion

        #region ICollection<T> Members

        public void Add(T item)
        {
            Data.Add(item);
        }

        public void Clear()
        {
            Data.Clear();
        }

        public bool Contains(T item)
        {
            return Data.Contains(item);
        }

        public void CopyTo(T[] array, int arrayIndex)
        {
            Data.CopyTo(array, arrayIndex);
        }

        public int Count
        {
            get { return Data.Count; }
        }

        public bool IsReadOnly
        {
            get { return false; }
        }

        public bool Remove(T item)
        {
            return Data.Remove(item);
        }

        #endregion

        #region IEnumerable<T> Members

        public IEnumerator<T> GetEnumerator()
        {
            return Data.GetEnumerator();
        }

        #endregion

        #region IEnumerable Members

        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            return Data.GetEnumerator();
        }

        #endregion
    }
}
